﻿@{
    Layout = "~/Views/Generic/_CodebehindLanguageSelector.cshtml";
}

@section cs_webforms
{using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Krystalware.SlickUpload;
using Krystalware.SlickUpload.Web.Controls;

namespace @ViewBag.Project.Name.@ViewBag.Sample.Path
{
    public partial class @(ViewBag.Sample.Path)Default : System.Web.UI.Page
    {
        @if (IsSectionDefined("cs_webforms_existing"))
        {
            @RenderSection("cs_webforms_existing")
        }
        else
        {
            if (ViewBag.Project.IsAspNetAjax)
            {
                <text>
        protected void updateButton_Click(object sender, EventArgs e)
        {
            updateLabel.Text = DateTime.Now.ToLongTimeString();
        }
                </text>
            }
        <text>
        protected void slickUpload_UploadComplete(object sender, UploadSessionEventArgs e)
        {
            uploadResultPanel.Visible = true;
            uploadPanel.Visible = false;

            if (e.UploadSession != null && e.UploadSession.State == UploadState.Complete)
            {
                if (e.UploadSession.UploadedFiles.Count > 0)
                {
                    @RenderSection("cs_webforms_uploadsuccess", false)
                    resultsRepeater.DataSource = e.UploadSession.UploadedFiles;
                    resultsRepeater.DataBind();
                }
            }            
        }

        protected void newUploadButton_Click(object sender, EventArgs e)
        {
            uploadResultPanel.Visible = false;
            uploadPanel.Visible = true;
        }        
        </text>
        }

        @RenderSection("cs_webforms_new", false)

        @if (ViewBag.Project.IsAspNetAjax)
        {
        <text>
        protected override void Render(HtmlTextWriter writer)
        {
            // Ensure ASP.NET AJAX controls initialize and render properly
            @RenderSection("cs_webforms_render_new", false)
            ClientScript.RegisterForEventValidation(newUploadButton.UniqueID);

            base.Render(writer);
        }
        </text>
        }
        else if (IsSectionDefined("cs_webforms_render_new"))
        {
            WriteTo(new StringWriter(), RenderSection("cs_webforms_render_new", false));            
        }
    }
}
}
@section vb_webforms {Imports Krystalware.SlickUpload
Imports Krystalware.SlickUpload.Web.Controls

Namespace @ViewBag.Sample.Path
    Public Class @(ViewBag.Sample.Path)Default
        Inherits System.Web.UI.Page

        @if (IsSectionDefined("vb_webforms_existing"))
        {
            @RenderSection("vb_webforms_existing")
        }
        else
        {
            if (ViewBag.Project.IsAspNetAjax)
            {
                <text>
        Protected Sub updateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles updateButton.Click
            updateLabel.Text = DateTime.Now.ToLongTimeString()
        End Sub
                </text>
            }
        <text>
        Protected Sub slickUpload_UploadComplete(ByVal sender As Object, ByVal e As UploadSessionEventArgs) Handles slickUpload.UploadComplete
            uploadResultPanel.Visible = True
            uploadPanel.Visible = False

            If Not e.UploadSession Is Nothing AndAlso e.UploadSession.State = UploadState.Complete Then
                If e.UploadSession.UploadedFiles.Count > 0 Then
                    @RenderSection("vb_webforms_uploadsuccess", false)
                    resultsRepeater.DataSource = e.UploadSession.UploadedFiles
                    resultsRepeater.DataBind()
                End If
            End If
        End Sub

        Protected Sub newUploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newUploadButton.Click
            uploadResultPanel.Visible = False
            uploadPanel.Visible = True
        End Sub
        </text>
        }

        @RenderSection("vb_webforms_new", false)

        @if (ViewBag.Project.IsAspNetAjax)
        {
        <text>
        Protected Overrides Sub Render(writer As HtmlTextWriter)
            'Ensure ASP.NET AJAX controls initialize and render properly
            @RenderSection("vb_webforms_render_new", false)
            ClientScript.RegisterForEventValidation(newUploadButton.UniqueID)

            MyBase.Render(writer)
        End Sub
        </text>
        }
        else if (IsSectionDefined("vb_webforms_render_new"))
        {
            WriteTo(new StringWriter(), RenderSection("vb_webforms_render_new", false));            
        }        
    End Class
End Namespace
}
@section cs_mvc {using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Krystalware.SlickUpload;
using @(ViewBag.Project.Name).Models;

namespace @(ViewBag.Project.Name).Controllers
{
    public class @(ViewBag.Sample.Path)Controller : Controller
    {
        @if (IsSectionDefined("cs_mvc_existing"))
        {
            @RenderSection("cs_mvc_existing")
        }
        else
        {
            if (ViewBag.Sample.HasModel)
            {
        <text>
        public ActionResult Index(@(ViewBag.Sample.Path)Model model)
        {
            if (model == null)
                model = new @(ViewBag.Sample.Path)Model();

            @RenderSection("cs_mvc_initmodel", false)

            return View(model);
        }

        public ActionResult UploadResult(@(ViewBag.Sample.Path)Model model, UploadSession session)
        {
            @RenderSection("cs_mvc_uploadsuccess", false)

            model.UploadSession = session;

            return View(model);
        }
        </text>
            }
            else
            {
        <text>
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult UploadResult(UploadSession session)
        {
            @RenderSection("cs_mvc_uploadsuccess", false)
            return View(session);
        }
        </text>
            }
        }

        @RenderSection("cs_mvc_new", false)
    }
}
}
@section vb_mvc {Imports Krystalware.SlickUpload
Imports @(ViewBag.Project.Name).Models

Public Class @(ViewBag.Sample.Path)Controller
    Inherits System.Web.Mvc.Controller

    @if (IsSectionDefined("vb_mvc_existing"))
    {
        @RenderSection("vb_mvc_existing")
    }
    else
    {
        if (ViewBag.Sample.HasModel)
        {
    <text>
    Public Function Index(model As @(ViewBag.Sample.Path)Model) As ActionResult
        If model Is Nothing Then
            model = New @(ViewBag.Sample.Path)Model()
        End If

        @RenderSection("vb_mvc_initmodel", false)

        Return View(model)
    End Function

    Public Function UploadResult(model As @(ViewBag.Sample.Path)Model, session As UploadSession) As ActionResult
        @RenderSection("vb_mvc_uploadsuccess", false)

        model.UploadSession = session

        Return View(model)
    End Function
    </text>
        }
        else
        {
    <text>
    Public Function Index() As ActionResult
        Return View()
    End Function

    Public Function UploadResult(session As UploadSession) As ActionResult
        @RenderSection("vb_mvc_uploadsuccess", false)
        Return View(session)
    End Function
    </text>
        }
    }

    @RenderSection("vb_mvc_new", false)    
End Class
}

@RenderBody()